
        let datas//存储数据

        //数据加载
        $.ajax({
            url: '../data_admin',
            type: "POST",
            success: function (data) {
                if (data.code == 0) {
                    $("#lasttime").text("上次登录时间：" + data.data[0].Last_time)
                    $.ajax({
                        url: '../admin_select_user',
                        type: 'POST',
                        success: function (data1) {
                            if (data1.code == 0) {
                                datas = data1.result

                                let contents = ``
                                $.each(data1.result, function (index, value) {
                                    contents += `<tr>
                <td>${value.UserID}</td>
                <td>${value.UserName}</td>
                <td>${value.Userpassword}</td>
                <td>${value.MenuNum}</td>
                <td>${value.Collection}</td>
                <td>${value.FansNum}</td>
                <td>${value.FocusNum}</td>
                <td><button class="btn btn-secondary"><a style="text-decoration: none;color:white"
                            href="../admin/user_detail.html/${value.UserID}">查看/修改</a></button>&nbsp;<button
                        class="delete_ btn btn-secondary">删除</button></td>
            </tr>`
                                })
                                $("#content").html(contents)
                            } else alert(data.data)
                        }
                    })
                }
            }
        })

        //搜索
        $("#search").on('input', function () {
            let searchtext = $(this).val()
            let contents = ``
            $.each(datas, function (index, value) {
                if (`${value.UserID}`.indexOf(searchtext) == 0 || value.UserName.indexOf(searchtext) == 0) {
                    contents += `<tr>
                <td>${value.UserID}</td>
                <td>${value.UserName}</td>
                <td>${value.Userpassword}</td>
                <td>${value.MenuNum}</td>
                <td>${value.Collection}</td>
                <td>${value.FansNum}</td>
                <td>${value.FocusNum}</td>
                <td><button class="btn btn-secondary"><a style="text-decoration: none;color:white"
                            href="#">查看/修改</a></button>&nbsp;<button
                        class="delete_ btn btn-secondary">删除</button></td>
            </tr>`
                }
            })
            $("#content").html(contents)
        })

        //退出登录
        $("#Exit").on('click', function () {
            $.ajax({
                url: '../admin/Exit',
                type: 'POST',
                success: function () {
                    window.location.href = '../'
                }
            })
        })

        //删除用户
        $("body").on('click', '.delete_ ', function () {
            $.ajax({
                url: '../admin/userdelete',
                type: "POST",
                data: {
                    UserID: $(this).parent().siblings().eq(0).text()
                },
                success: function (data) {
                    if (data.code == 0) {
                        alert('删除成功')
                        window.location.href = './head.html'
                    }
                }
            })
        })

        //添加用户页面
        $("#AddUser").on('click', function () {
            $(".add").html(`<thead>
            <tr>
                <th scope="col">ID</th>
                <th scope="col">用户名</th>
                <th scope="col">用户密码</th>
                <th scope="col">用户头像</th>
                <th scope="col">操作</th>
            </tr>
        </thead>
        <tbody>
                <td><input type="text"></td>
                <td><input type="text"></td>
                <td><input type="text"></td>
                <td>
                <input type="file" class="form-control" id="picture">
                </td>
                <td>
                <button class="save btn btn-secondary">保存</button>
                </td>
        </tbody>`)
        })

        //提交注册
        $("body").on('click', '.save', function () {
            let data_text = $(this).parent().siblings()
            let picture = new FormData()
            if (data_text.eq(0).children().val() != '' && data_text.eq(1).children().val() != '' && data_text.eq(2).children().val() != '' && $("#picture")[0].files[0]) {
                $.ajax({
                    url: '../insert_user',
                    type: "POST",
                    data: {
                        UserID: data_text.eq(0).children().val(),
                        UserName: data_text.eq(1).children().val(),
                        UserPassword: data_text.eq(2).children().val()
                    }, success: function (data) {
                        if (data.code == 0) {
                            picture.append("UserID", data.UserID)
                            picture.append("file", $("#picture")[0].files[0])
                            $.ajax({
                                url: '../admin_userimg_add',
                                type: "POST",
                                data: picture,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    alert(data_text.eq(1).children().val() + '：添加成功')
                                    window.location.href = './head.html'

                                    console.log(data);
                                }
                            })
                            // window.location.href = './head.html'
                        } else alert(data.result)
                    }
                })
            } else alert('请将信息填写完整')
        })
    